package com.wsc.wisdomchina.ai.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;

import com.wsc.wisdomchina.R;


/**
 * 点击就能缩放的按钮哟
 * 
 * @author 沈宇坤
 * @time 下午5:48:10
 */
public class MyScaleButton extends Button {

	/**
	 * 构造函数
	 * 
	 * @param context
	 */
	public MyScaleButton(Context context) {
		super(context);
	}

	/**
	 * @param context
	 * @param attrs
	 * @param defStyle
	 */
	public MyScaleButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	/**
	 * @param context
	 * @param attrs
	 */
	public MyScaleButton(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@SuppressLint("ClickableViewAccessibility")
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_UP) {
			// ScaleAnimation mScaleAnimation = new ScaleAnimation(0.4f, 1.0f,
			// 0.4f, 1f, Animation.RELATIVE_TO_SELF, 0.5f,
			// Animation.RELATIVE_TO_SELF, 0.5f);
			// mScaleAnimation.setDuration(1000);
			Animation scaleAnimation;
			final Animation scaleAnimation2;
			// 从大到小的动画
			scaleAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.scale_to_small);
			// 从小到大的动画
			scaleAnimation2 = AnimationUtils.loadAnimation(getContext(), R.anim.scale_to_normal);
			this.startAnimation(scaleAnimation);
			scaleAnimation.setAnimationListener(new AnimationListener() {

				@Override
				public void onAnimationStart(Animation animation) {

				}

				@Override
				public void onAnimationRepeat(Animation animation) {

				}

				@Override
				public void onAnimationEnd(Animation animation) {
					MyScaleButton.this.startAnimation(scaleAnimation2);
				}
			});
		}
		return super.onTouchEvent(event);
	}

	@Override
	public boolean performClick() {
		return super.performClick();
	}

}
